﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using ModbusTestTool.Singeltons;
namespace ModbusTestTool.UI
{
    public partial class SettingsPaneV2 : UserControl
    {
        public SettingsPaneV2()
        {
            InitializeComponent();
            comboBox1.DataSource = new string[] { "Serial", "TCP/IP" };

        }

        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            RemoveExistingPanel();

            if ((string)comboBox1.SelectedValue == ((string[])comboBox1.DataSource)[0])
            {
                panel1.Controls.Add(new SettingsPane());
                setPanelAnchor(panel1.Controls[0]);
                Settings.Instance.State.serialOrTcpSelect = Settings.serialOrTcp.serial;
            }
            else
            {
                panel1.Controls.Add(new TCPpanel());
                setPanelAnchor(panel1.Controls[0]);
                Settings.Instance.State.serialOrTcpSelect = Settings.serialOrTcp.tcp;
            }
        }

        void RemoveExistingPanel()
        {
            if (panel1.Controls.Count != 0)
            {
                panel1.Controls.RemoveAt(0);
                
            }
        }

        void setPanelAnchor(Control panel)
        {
            panel.Anchor = (AnchorStyles.Top | AnchorStyles.Right | AnchorStyles.Left | AnchorStyles.Bottom);
            panel.Dock = DockStyle.Fill;
        }


    }
}
